package com.lagou.cl.client.handler;

import com.alibaba.fastjson.JSONObject;
import com.lagou.cl.client.RpcConsumer;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 程  林
 * @date 2020-05-23 19:06
 * @description //
 * @since V1.0.0
 */
@ChannelHandler.Sharable
public class AccountClientHandler extends SimpleChannelInboundHandler<String> {

	private Logger logger = LoggerFactory.getLogger(AccountClientHandler.class);

	/**
	 * 收到服务器端的响应,
	 *
	 * @param ctx
	 * @param msg
	 * @throws Exception
	 */
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		//{"isSuccess":true,"requestId":"e214b51b-ab52-4e58-b406-a734a011b69e","result":"success"}

		RpcConsumer.getDataMap().put(JSONObject.parseObject(msg).getString("requestId"), msg);
		logger.info("dataMap：{}", RpcConsumer.getDataMap());

	}
}
